//
//  UAVClientViewController.h
//  UAVClient
//
//  Created by visu4l on 11. 6. 29..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

#import <CoreMotion/CoreMotion.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>

//video
#import <AVFoundation/AVFoundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <CoreVideo/CoreVideo.h>
#import <CoreMedia/CoreMedia.h>
//end video

#import "NetworkController.h"
#import "SendPacket.h"
#import "RecvPacket.h"
#import "SensorModel.h"

#import "MotionSensor.h"
#import "LocationSensor.h"
#import "CameraSensor.h"

@interface UAVClientViewController : UIViewController < UIImagePickerControllerDelegate, AVCaptureVideoDataOutputSampleBufferDelegate > {

    SensorModel *sensorModel;
    MotionSensor *motionSensor;
    LocationSensor *locationSensor;
    
    NetworkController *controller;
    
    UIImagePickerController *imagePickerController;
    
    NSTimer *updateModelTimer;
     
    //basic ui
    IBOutlet UIButton *btnConnect;
    IBOutlet UITextView *textStatus;
    IBOutlet UIImageView *compassImg;
    
    IBOutlet UIImageView *pictureView;
    IBOutlet UIButton * btnPicture;
    
    //test ui
    IBOutlet UITextField *textLat;
    IBOutlet UITextField *textLng;
    IBOutlet UITextField *textAlt;

    IBOutlet UITextField *textLocationAcc;
    IBOutlet UITextField *textAltAcc;
    IBOutlet UITextField *textSpeed;
    
    IBOutlet UITextField *textRoll;
    IBOutlet UITextField *textPitch;
    IBOutlet UITextField *textYaw;
    
    IBOutlet UITextField *textHeading;
    
    
    //Video
    
    AVCaptureSession *captureSession;
    UIImageView *imageView;
    CALayer *customLayer;
    AVCaptureVideoPreviewLayer *prevLayer;
}

@property (nonatomic, retain) SensorModel *sensorModel;;
@property (nonatomic, retain) MotionSensor *motionSensor;;
@property (nonatomic, retain) LocationSensor *locationSensor;

@property (nonatomic, retain) NetworkController *controller;
@property (nonatomic, retain) UIImagePickerController *imagePickerController;

@property (nonatomic, retain) IBOutlet UIImageView *pictureView;

@property (nonatomic, retain) IBOutlet UIButton *btnConnect;
@property (nonatomic, retain) IBOutlet UITextView *textStatus;
@property (nonatomic, retain) IBOutlet UIImageView *compassImg;

@property (nonatomic, retain) IBOutlet UITextField *textLat;
@property (nonatomic, retain) IBOutlet UITextField *textLng;
@property (nonatomic, retain) IBOutlet UITextField *textAlt;

@property (nonatomic, retain) IBOutlet UITextField *textLocationAcc;
@property (nonatomic, retain) IBOutlet UITextField *textAltAcc;
@property (nonatomic, retain) IBOutlet UITextField *textSpeed;

@property (nonatomic, retain) IBOutlet UITextField *textRoll;
@property (nonatomic, retain) IBOutlet UITextField *textPitch;
@property (nonatomic, retain) IBOutlet UITextField *textYaw;

@property (nonatomic, retain) IBOutlet UITextField *textHeading;

-(void) setup;
-(IBAction) clickConnect:(id) sender;
-(IBAction) clickSend:(id) sender;
-(Boolean) isNetworkReachable;
-(IBAction) clickPicture:(id) sender;

-(void) updateModel;
-(void) makeSendPacket;
-(void) printStatus:(NSString *)msg;

//video

@property (nonatomic, retain) AVCaptureSession *captureSession;
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) CALayer *customLayer;
@property (nonatomic, retain)AVCaptureVideoPreviewLayer *prevLayer;

-(void) initCapture;
// end video

@end
